import 'package:package_info_plus/package_info_plus.dart';

/// APP信息模型
class PackageInfoModel {
  /// app 名称
  final String? appName;

  /// 包名（app 的唯一标识）：The package name. `bundleIdentifier` on iOS, `getPackageName` on Android.
  final String? packageName;

  /// 版本号：The package version. `CFBundleShortVersionString` on iOS, `versionName` on Android.
  /// FLUTTER_BUILD_NAME
  final String? version;

  /// The build number. `CFBundleVersion` on iOS, `versionCode` on Android.
  /// FLUTTER_BUILD_NUMBER
  final String? buildNumber;

  PackageInfoModel({
    this.appName,
    this.packageName,
    this.version,
    this.buildNumber,
  });

  ///
  /// 获取APP信息
  ///
  static Future<PackageInfoModel> getPackageInfo() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();

    PackageInfoModel info = PackageInfoModel(
      appName: packageInfo.appName,
      packageName: packageInfo.packageName,
      version: packageInfo.version,
      buildNumber: packageInfo.buildNumber,
    );

    return info;
  }
}
